/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.caresms.service.persistence;

import com.caresms.NoSuchKeyword_MasterException;

import com.caresms.model.Keyword_Master;
import com.caresms.model.impl.Keyword_MasterImpl;
import com.caresms.model.impl.Keyword_MasterModelImpl;

import com.liferay.portal.NoSuchModelException;
import com.liferay.portal.kernel.bean.BeanReference;
import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.BatchSessionUtil;
import com.liferay.portal.service.persistence.ResourcePersistence;
import com.liferay.portal.service.persistence.UserPersistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the keyword_ master service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author cc
 * @see Keyword_MasterPersistence
 * @see Keyword_MasterUtil
 * @generated
 */
public class Keyword_MasterPersistenceImpl extends BasePersistenceImpl<Keyword_Master>
	implements Keyword_MasterPersistence {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. Always use {@link Keyword_MasterUtil} to access the keyword_ master persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
	 */
	public static final String FINDER_CLASS_NAME_ENTITY = Keyword_MasterImpl.class.getName();
	public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List1";
	public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
		".List2";
	public static final FinderPath FINDER_PATH_FETCH_BY_FINDKEYWORDBYID = new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED,
			Keyword_MasterImpl.class, FINDER_CLASS_NAME_ENTITY,
			"fetchByFindKeywordById", new String[] { Long.class.getName() },
			Keyword_MasterModelImpl.KEYID_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_FINDKEYWORDBYID = new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countByFindKeywordById", new String[] { Long.class.getName() });
	public static final FinderPath FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME = new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED,
			Keyword_MasterImpl.class, FINDER_CLASS_NAME_ENTITY,
			"fetchByFindKeywordByName",
			new String[] { String.class.getName() },
			Keyword_MasterModelImpl.KEYWORDNAME_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME = new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countByFindKeywordByName", new String[] { String.class.getName() });
	public static final FinderPath FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY =
		new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED,
			Keyword_MasterImpl.class, FINDER_CLASS_NAME_ENTITY,
			"fetchByFindKeywordByName_createdBy",
			new String[] { String.class.getName(), Long.class.getName() },
			Keyword_MasterModelImpl.KEYWORDNAME_COLUMN_BITMASK |
			Keyword_MasterModelImpl.CREATED_BY_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME_CREATEDBY =
		new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countByFindKeywordByName_createdBy",
			new String[] { String.class.getName(), Long.class.getName() });
	public static final FinderPath FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE =
		new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED,
			Keyword_MasterImpl.class, FINDER_CLASS_NAME_ENTITY,
			"fetchByFindKeywordByName_isActive",
			new String[] { String.class.getName(), Boolean.class.getName() },
			Keyword_MasterModelImpl.KEYWORDNAME_COLUMN_BITMASK |
			Keyword_MasterModelImpl.ISACTIVE_COLUMN_BITMASK);
	public static final FinderPath FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME_ISACTIVE =
		new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
			"countByFindKeywordByName_isActive",
			new String[] { String.class.getName(), Boolean.class.getName() });
	public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED,
			Keyword_MasterImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
			"findAll", new String[0]);
	public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED,
			Keyword_MasterImpl.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
	public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterModelImpl.FINDER_CACHE_ENABLED, Long.class,
			FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);

	/**
	 * Caches the keyword_ master in the entity cache if it is enabled.
	 *
	 * @param keyword_Master the keyword_ master
	 */
	public void cacheResult(Keyword_Master keyword_Master) {
		EntityCacheUtil.putResult(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterImpl.class, keyword_Master.getPrimaryKey(),
			keyword_Master);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYID,
			new Object[] { Long.valueOf(keyword_Master.getKeyId()) },
			keyword_Master);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME,
			new Object[] { keyword_Master.getKeywordName() }, keyword_Master);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY,
			new Object[] {
				keyword_Master.getKeywordName(),
				Long.valueOf(keyword_Master.getCreated_By())
			}, keyword_Master);

		FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE,
			new Object[] {
				keyword_Master.getKeywordName(),
				Boolean.valueOf(keyword_Master.getIsActive())
			}, keyword_Master);

		keyword_Master.resetOriginalValues();
	}

	/**
	 * Caches the keyword_ masters in the entity cache if it is enabled.
	 *
	 * @param keyword_Masters the keyword_ masters
	 */
	public void cacheResult(List<Keyword_Master> keyword_Masters) {
		for (Keyword_Master keyword_Master : keyword_Masters) {
			if (EntityCacheUtil.getResult(
						Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
						Keyword_MasterImpl.class, keyword_Master.getPrimaryKey()) == null) {
				cacheResult(keyword_Master);
			}
			else {
				keyword_Master.resetOriginalValues();
			}
		}
	}

	/**
	 * Clears the cache for all keyword_ masters.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache() {
		if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
			CacheRegistryUtil.clear(Keyword_MasterImpl.class.getName());
		}

		EntityCacheUtil.clearCache(Keyword_MasterImpl.class.getName());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	/**
	 * Clears the cache for the keyword_ master.
	 *
	 * <p>
	 * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
	 * </p>
	 */
	@Override
	public void clearCache(Keyword_Master keyword_Master) {
		EntityCacheUtil.removeResult(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterImpl.class, keyword_Master.getPrimaryKey());

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		clearUniqueFindersCache(keyword_Master);
	}

	@Override
	public void clearCache(List<Keyword_Master> keyword_Masters) {
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		for (Keyword_Master keyword_Master : keyword_Masters) {
			EntityCacheUtil.removeResult(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
				Keyword_MasterImpl.class, keyword_Master.getPrimaryKey());

			clearUniqueFindersCache(keyword_Master);
		}
	}

	protected void clearUniqueFindersCache(Keyword_Master keyword_Master) {
		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYID,
			new Object[] { Long.valueOf(keyword_Master.getKeyId()) });

		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME,
			new Object[] { keyword_Master.getKeywordName() });

		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY,
			new Object[] {
				keyword_Master.getKeywordName(),
				Long.valueOf(keyword_Master.getCreated_By())
			});

		FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE,
			new Object[] {
				keyword_Master.getKeywordName(),
				Boolean.valueOf(keyword_Master.getIsActive())
			});
	}

	/**
	 * Creates a new keyword_ master with the primary key. Does not add the keyword_ master to the database.
	 *
	 * @param KeyId the primary key for the new keyword_ master
	 * @return the new keyword_ master
	 */
	public Keyword_Master create(long KeyId) {
		Keyword_Master keyword_Master = new Keyword_MasterImpl();

		keyword_Master.setNew(true);
		keyword_Master.setPrimaryKey(KeyId);

		return keyword_Master;
	}

	/**
	 * Removes the keyword_ master with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param KeyId the primary key of the keyword_ master
	 * @return the keyword_ master that was removed
	 * @throws com.caresms.NoSuchKeyword_MasterException if a keyword_ master with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master remove(long KeyId)
		throws NoSuchKeyword_MasterException, SystemException {
		return remove(Long.valueOf(KeyId));
	}

	/**
	 * Removes the keyword_ master with the primary key from the database. Also notifies the appropriate model listeners.
	 *
	 * @param primaryKey the primary key of the keyword_ master
	 * @return the keyword_ master that was removed
	 * @throws com.caresms.NoSuchKeyword_MasterException if a keyword_ master with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Keyword_Master remove(Serializable primaryKey)
		throws NoSuchKeyword_MasterException, SystemException {
		Session session = null;

		try {
			session = openSession();

			Keyword_Master keyword_Master = (Keyword_Master)session.get(Keyword_MasterImpl.class,
					primaryKey);

			if (keyword_Master == null) {
				if (_log.isWarnEnabled()) {
					_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
				}

				throw new NoSuchKeyword_MasterException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
					primaryKey);
			}

			return remove(keyword_Master);
		}
		catch (NoSuchKeyword_MasterException nsee) {
			throw nsee;
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}
	}

	@Override
	protected Keyword_Master removeImpl(Keyword_Master keyword_Master)
		throws SystemException {
		keyword_Master = toUnwrappedModel(keyword_Master);

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.delete(session, keyword_Master);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		clearCache(keyword_Master);

		return keyword_Master;
	}

	@Override
	public Keyword_Master updateImpl(
		com.caresms.model.Keyword_Master keyword_Master, boolean merge)
		throws SystemException {
		keyword_Master = toUnwrappedModel(keyword_Master);

		boolean isNew = keyword_Master.isNew();

		Keyword_MasterModelImpl keyword_MasterModelImpl = (Keyword_MasterModelImpl)keyword_Master;

		Session session = null;

		try {
			session = openSession();

			BatchSessionUtil.update(session, keyword_Master, merge);

			keyword_Master.setNew(false);
		}
		catch (Exception e) {
			throw processException(e);
		}
		finally {
			closeSession(session);
		}

		FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

		if (isNew || !Keyword_MasterModelImpl.COLUMN_BITMASK_ENABLED) {
			FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
		}

		EntityCacheUtil.putResult(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
			Keyword_MasterImpl.class, keyword_Master.getPrimaryKey(),
			keyword_Master);

		if (isNew) {
			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYID,
				new Object[] { Long.valueOf(keyword_Master.getKeyId()) },
				keyword_Master);

			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME,
				new Object[] { keyword_Master.getKeywordName() }, keyword_Master);

			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY,
				new Object[] {
					keyword_Master.getKeywordName(),
					Long.valueOf(keyword_Master.getCreated_By())
				}, keyword_Master);

			FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE,
				new Object[] {
					keyword_Master.getKeywordName(),
					Boolean.valueOf(keyword_Master.getIsActive())
				}, keyword_Master);
		}
		else {
			if ((keyword_MasterModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_FINDKEYWORDBYID.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						Long.valueOf(keyword_MasterModelImpl.getOriginalKeyId())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYID,
					args);

				FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYID,
					args);

				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYID,
					new Object[] { Long.valueOf(keyword_Master.getKeyId()) },
					keyword_Master);
			}

			if ((keyword_MasterModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						keyword_MasterModelImpl.getOriginalKeywordName()
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME,
					args);

				FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME,
					args);

				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME,
					new Object[] { keyword_Master.getKeywordName() },
					keyword_Master);
			}

			if ((keyword_MasterModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						keyword_MasterModelImpl.getOriginalKeywordName(),
						Long.valueOf(keyword_MasterModelImpl.getOriginalCreated_By())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME_CREATEDBY,
					args);

				FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY,
					args);

				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY,
					new Object[] {
						keyword_Master.getKeywordName(),
						Long.valueOf(keyword_Master.getCreated_By())
					}, keyword_Master);
			}

			if ((keyword_MasterModelImpl.getColumnBitmask() &
					FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE.getColumnBitmask()) != 0) {
				Object[] args = new Object[] {
						keyword_MasterModelImpl.getOriginalKeywordName(),
						Boolean.valueOf(keyword_MasterModelImpl.getOriginalIsActive())
					};

				FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME_ISACTIVE,
					args);

				FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE,
					args);

				FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE,
					new Object[] {
						keyword_Master.getKeywordName(),
						Boolean.valueOf(keyword_Master.getIsActive())
					}, keyword_Master);
			}
		}

		return keyword_Master;
	}

	protected Keyword_Master toUnwrappedModel(Keyword_Master keyword_Master) {
		if (keyword_Master instanceof Keyword_MasterImpl) {
			return keyword_Master;
		}

		Keyword_MasterImpl keyword_MasterImpl = new Keyword_MasterImpl();

		keyword_MasterImpl.setNew(keyword_Master.isNew());
		keyword_MasterImpl.setPrimaryKey(keyword_Master.getPrimaryKey());

		keyword_MasterImpl.setKeyId(keyword_Master.getKeyId());
		keyword_MasterImpl.setCompanyId(keyword_Master.getCompanyId());
		keyword_MasterImpl.setUserId(keyword_Master.getUserId());
		keyword_MasterImpl.setKeywordName(keyword_Master.getKeywordName());
		keyword_MasterImpl.setCreateDate(keyword_Master.getCreateDate());
		keyword_MasterImpl.setCreated_By(keyword_Master.getCreated_By());
		keyword_MasterImpl.setIsActive(keyword_Master.isIsActive());
		keyword_MasterImpl.setCat_Id(keyword_Master.getCat_Id());
		keyword_MasterImpl.setField1(keyword_Master.getField1());
		keyword_MasterImpl.setField2(keyword_Master.isField2());
		keyword_MasterImpl.setField3(keyword_Master.getField3());
		keyword_MasterImpl.setField4(keyword_Master.getField4());
		keyword_MasterImpl.setField5(keyword_Master.getField5());

		return keyword_MasterImpl;
	}

	/**
	 * Returns the keyword_ master with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
	 *
	 * @param primaryKey the primary key of the keyword_ master
	 * @return the keyword_ master
	 * @throws com.liferay.portal.NoSuchModelException if a keyword_ master with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Keyword_Master findByPrimaryKey(Serializable primaryKey)
		throws NoSuchModelException, SystemException {
		return findByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the keyword_ master with the primary key or throws a {@link com.caresms.NoSuchKeyword_MasterException} if it could not be found.
	 *
	 * @param KeyId the primary key of the keyword_ master
	 * @return the keyword_ master
	 * @throws com.caresms.NoSuchKeyword_MasterException if a keyword_ master with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master findByPrimaryKey(long KeyId)
		throws NoSuchKeyword_MasterException, SystemException {
		Keyword_Master keyword_Master = fetchByPrimaryKey(KeyId);

		if (keyword_Master == null) {
			if (_log.isWarnEnabled()) {
				_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + KeyId);
			}

			throw new NoSuchKeyword_MasterException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
				KeyId);
		}

		return keyword_Master;
	}

	/**
	 * Returns the keyword_ master with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param primaryKey the primary key of the keyword_ master
	 * @return the keyword_ master, or <code>null</code> if a keyword_ master with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	@Override
	public Keyword_Master fetchByPrimaryKey(Serializable primaryKey)
		throws SystemException {
		return fetchByPrimaryKey(((Long)primaryKey).longValue());
	}

	/**
	 * Returns the keyword_ master with the primary key or returns <code>null</code> if it could not be found.
	 *
	 * @param KeyId the primary key of the keyword_ master
	 * @return the keyword_ master, or <code>null</code> if a keyword_ master with the primary key could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master fetchByPrimaryKey(long KeyId)
		throws SystemException {
		Keyword_Master keyword_Master = (Keyword_Master)EntityCacheUtil.getResult(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
				Keyword_MasterImpl.class, KeyId);

		if (keyword_Master == _nullKeyword_Master) {
			return null;
		}

		if (keyword_Master == null) {
			Session session = null;

			boolean hasException = false;

			try {
				session = openSession();

				keyword_Master = (Keyword_Master)session.get(Keyword_MasterImpl.class,
						Long.valueOf(KeyId));
			}
			catch (Exception e) {
				hasException = true;

				throw processException(e);
			}
			finally {
				if (keyword_Master != null) {
					cacheResult(keyword_Master);
				}
				else if (!hasException) {
					EntityCacheUtil.putResult(Keyword_MasterModelImpl.ENTITY_CACHE_ENABLED,
						Keyword_MasterImpl.class, KeyId, _nullKeyword_Master);
				}

				closeSession(session);
			}
		}

		return keyword_Master;
	}

	/**
	 * Returns the keyword_ master where KeyId = &#63; or throws a {@link com.caresms.NoSuchKeyword_MasterException} if it could not be found.
	 *
	 * @param KeyId the key ID
	 * @return the matching keyword_ master
	 * @throws com.caresms.NoSuchKeyword_MasterException if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master findByFindKeywordById(long KeyId)
		throws NoSuchKeyword_MasterException, SystemException {
		Keyword_Master keyword_Master = fetchByFindKeywordById(KeyId);

		if (keyword_Master == null) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("KeyId=");
			msg.append(KeyId);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchKeyword_MasterException(msg.toString());
		}

		return keyword_Master;
	}

	/**
	 * Returns the keyword_ master where KeyId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param KeyId the key ID
	 * @return the matching keyword_ master, or <code>null</code> if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master fetchByFindKeywordById(long KeyId)
		throws SystemException {
		return fetchByFindKeywordById(KeyId, true);
	}

	/**
	 * Returns the keyword_ master where KeyId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param KeyId the key ID
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching keyword_ master, or <code>null</code> if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master fetchByFindKeywordById(long KeyId,
		boolean retrieveFromCache) throws SystemException {
		Object[] finderArgs = new Object[] { KeyId };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYID,
					finderArgs, this);
		}

		if (result instanceof Keyword_Master) {
			Keyword_Master keyword_Master = (Keyword_Master)result;

			if ((KeyId != keyword_Master.getKeyId())) {
				result = null;
			}
		}

		if (result == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_SELECT_KEYWORD_MASTER_WHERE);

			query.append(_FINDER_COLUMN_FINDKEYWORDBYID_KEYID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(KeyId);

				List<Keyword_Master> list = q.list();

				result = list;

				Keyword_Master keyword_Master = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYID,
						finderArgs, list);
				}
				else {
					keyword_Master = list.get(0);

					cacheResult(keyword_Master);

					if ((keyword_Master.getKeyId() != KeyId)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYID,
							finderArgs, keyword_Master);
					}
				}

				return keyword_Master;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYID,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (Keyword_Master)result;
			}
		}
	}

	/**
	 * Returns the keyword_ master where KeywordName = &#63; or throws a {@link com.caresms.NoSuchKeyword_MasterException} if it could not be found.
	 *
	 * @param KeywordName the keyword name
	 * @return the matching keyword_ master
	 * @throws com.caresms.NoSuchKeyword_MasterException if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master findByFindKeywordByName(String KeywordName)
		throws NoSuchKeyword_MasterException, SystemException {
		Keyword_Master keyword_Master = fetchByFindKeywordByName(KeywordName);

		if (keyword_Master == null) {
			StringBundler msg = new StringBundler(4);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("KeywordName=");
			msg.append(KeywordName);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchKeyword_MasterException(msg.toString());
		}

		return keyword_Master;
	}

	/**
	 * Returns the keyword_ master where KeywordName = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param KeywordName the keyword name
	 * @return the matching keyword_ master, or <code>null</code> if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master fetchByFindKeywordByName(String KeywordName)
		throws SystemException {
		return fetchByFindKeywordByName(KeywordName, true);
	}

	/**
	 * Returns the keyword_ master where KeywordName = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param KeywordName the keyword name
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching keyword_ master, or <code>null</code> if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master fetchByFindKeywordByName(String KeywordName,
		boolean retrieveFromCache) throws SystemException {
		Object[] finderArgs = new Object[] { KeywordName };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME,
					finderArgs, this);
		}

		if (result instanceof Keyword_Master) {
			Keyword_Master keyword_Master = (Keyword_Master)result;

			if (!Validator.equals(KeywordName, keyword_Master.getKeywordName())) {
				result = null;
			}
		}

		if (result == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_SELECT_KEYWORD_MASTER_WHERE);

			if (KeywordName == null) {
				query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_KEYWORDNAME_1);
			}
			else {
				if (KeywordName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_KEYWORDNAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_KEYWORDNAME_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (KeywordName != null) {
					qPos.add(KeywordName);
				}

				List<Keyword_Master> list = q.list();

				result = list;

				Keyword_Master keyword_Master = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME,
						finderArgs, list);
				}
				else {
					keyword_Master = list.get(0);

					cacheResult(keyword_Master);

					if ((keyword_Master.getKeywordName() == null) ||
							!keyword_Master.getKeywordName().equals(KeywordName)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME,
							finderArgs, keyword_Master);
					}
				}

				return keyword_Master;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (Keyword_Master)result;
			}
		}
	}

	/**
	 * Returns the keyword_ master where KeywordName = &#63; and Created_By = &#63; or throws a {@link com.caresms.NoSuchKeyword_MasterException} if it could not be found.
	 *
	 * @param KeywordName the keyword name
	 * @param Created_By the created_ by
	 * @return the matching keyword_ master
	 * @throws com.caresms.NoSuchKeyword_MasterException if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master findByFindKeywordByName_createdBy(
		String KeywordName, long Created_By)
		throws NoSuchKeyword_MasterException, SystemException {
		Keyword_Master keyword_Master = fetchByFindKeywordByName_createdBy(KeywordName,
				Created_By);

		if (keyword_Master == null) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("KeywordName=");
			msg.append(KeywordName);

			msg.append(", Created_By=");
			msg.append(Created_By);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchKeyword_MasterException(msg.toString());
		}

		return keyword_Master;
	}

	/**
	 * Returns the keyword_ master where KeywordName = &#63; and Created_By = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param KeywordName the keyword name
	 * @param Created_By the created_ by
	 * @return the matching keyword_ master, or <code>null</code> if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master fetchByFindKeywordByName_createdBy(
		String KeywordName, long Created_By) throws SystemException {
		return fetchByFindKeywordByName_createdBy(KeywordName, Created_By, true);
	}

	/**
	 * Returns the keyword_ master where KeywordName = &#63; and Created_By = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param KeywordName the keyword name
	 * @param Created_By the created_ by
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching keyword_ master, or <code>null</code> if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master fetchByFindKeywordByName_createdBy(
		String KeywordName, long Created_By, boolean retrieveFromCache)
		throws SystemException {
		Object[] finderArgs = new Object[] { KeywordName, Created_By };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY,
					finderArgs, this);
		}

		if (result instanceof Keyword_Master) {
			Keyword_Master keyword_Master = (Keyword_Master)result;

			if (!Validator.equals(KeywordName, keyword_Master.getKeywordName()) ||
					(Created_By != keyword_Master.getCreated_By())) {
				result = null;
			}
		}

		if (result == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_SELECT_KEYWORD_MASTER_WHERE);

			if (KeywordName == null) {
				query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_KEYWORDNAME_1);
			}
			else {
				if (KeywordName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_KEYWORDNAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_KEYWORDNAME_2);
				}
			}

			query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_CREATED_BY_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (KeywordName != null) {
					qPos.add(KeywordName);
				}

				qPos.add(Created_By);

				List<Keyword_Master> list = q.list();

				result = list;

				Keyword_Master keyword_Master = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY,
						finderArgs, list);
				}
				else {
					keyword_Master = list.get(0);

					cacheResult(keyword_Master);

					if ((keyword_Master.getKeywordName() == null) ||
							!keyword_Master.getKeywordName().equals(KeywordName) ||
							(keyword_Master.getCreated_By() != Created_By)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY,
							finderArgs, keyword_Master);
					}
				}

				return keyword_Master;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_CREATEDBY,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (Keyword_Master)result;
			}
		}
	}

	/**
	 * Returns the keyword_ master where KeywordName = &#63; and isActive = &#63; or throws a {@link com.caresms.NoSuchKeyword_MasterException} if it could not be found.
	 *
	 * @param KeywordName the keyword name
	 * @param isActive the is active
	 * @return the matching keyword_ master
	 * @throws com.caresms.NoSuchKeyword_MasterException if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master findByFindKeywordByName_isActive(String KeywordName,
		boolean isActive) throws NoSuchKeyword_MasterException, SystemException {
		Keyword_Master keyword_Master = fetchByFindKeywordByName_isActive(KeywordName,
				isActive);

		if (keyword_Master == null) {
			StringBundler msg = new StringBundler(6);

			msg.append(_NO_SUCH_ENTITY_WITH_KEY);

			msg.append("KeywordName=");
			msg.append(KeywordName);

			msg.append(", isActive=");
			msg.append(isActive);

			msg.append(StringPool.CLOSE_CURLY_BRACE);

			if (_log.isWarnEnabled()) {
				_log.warn(msg.toString());
			}

			throw new NoSuchKeyword_MasterException(msg.toString());
		}

		return keyword_Master;
	}

	/**
	 * Returns the keyword_ master where KeywordName = &#63; and isActive = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
	 *
	 * @param KeywordName the keyword name
	 * @param isActive the is active
	 * @return the matching keyword_ master, or <code>null</code> if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master fetchByFindKeywordByName_isActive(
		String KeywordName, boolean isActive) throws SystemException {
		return fetchByFindKeywordByName_isActive(KeywordName, isActive, true);
	}

	/**
	 * Returns the keyword_ master where KeywordName = &#63; and isActive = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
	 *
	 * @param KeywordName the keyword name
	 * @param isActive the is active
	 * @param retrieveFromCache whether to use the finder cache
	 * @return the matching keyword_ master, or <code>null</code> if a matching keyword_ master could not be found
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master fetchByFindKeywordByName_isActive(
		String KeywordName, boolean isActive, boolean retrieveFromCache)
		throws SystemException {
		Object[] finderArgs = new Object[] { KeywordName, isActive };

		Object result = null;

		if (retrieveFromCache) {
			result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE,
					finderArgs, this);
		}

		if (result instanceof Keyword_Master) {
			Keyword_Master keyword_Master = (Keyword_Master)result;

			if (!Validator.equals(KeywordName, keyword_Master.getKeywordName()) ||
					(isActive != keyword_Master.getIsActive())) {
				result = null;
			}
		}

		if (result == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_SELECT_KEYWORD_MASTER_WHERE);

			if (KeywordName == null) {
				query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_KEYWORDNAME_1);
			}
			else {
				if (KeywordName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_KEYWORDNAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_KEYWORDNAME_2);
				}
			}

			query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_ISACTIVE_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (KeywordName != null) {
					qPos.add(KeywordName);
				}

				qPos.add(isActive);

				List<Keyword_Master> list = q.list();

				result = list;

				Keyword_Master keyword_Master = null;

				if (list.isEmpty()) {
					FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE,
						finderArgs, list);
				}
				else {
					keyword_Master = list.get(0);

					cacheResult(keyword_Master);

					if ((keyword_Master.getKeywordName() == null) ||
							!keyword_Master.getKeywordName().equals(KeywordName) ||
							(keyword_Master.getIsActive() != isActive)) {
						FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE,
							finderArgs, keyword_Master);
					}
				}

				return keyword_Master;
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (result == null) {
					FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FINDKEYWORDBYNAME_ISACTIVE,
						finderArgs);
				}

				closeSession(session);
			}
		}
		else {
			if (result instanceof List<?>) {
				return null;
			}
			else {
				return (Keyword_Master)result;
			}
		}
	}

	/**
	 * Returns all the keyword_ masters.
	 *
	 * @return the keyword_ masters
	 * @throws SystemException if a system exception occurred
	 */
	public List<Keyword_Master> findAll() throws SystemException {
		return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
	}

	/**
	 * Returns a range of all the keyword_ masters.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of keyword_ masters
	 * @param end the upper bound of the range of keyword_ masters (not inclusive)
	 * @return the range of keyword_ masters
	 * @throws SystemException if a system exception occurred
	 */
	public List<Keyword_Master> findAll(int start, int end)
		throws SystemException {
		return findAll(start, end, null);
	}

	/**
	 * Returns an ordered range of all the keyword_ masters.
	 *
	 * <p>
	 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
	 * </p>
	 *
	 * @param start the lower bound of the range of keyword_ masters
	 * @param end the upper bound of the range of keyword_ masters (not inclusive)
	 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
	 * @return the ordered range of keyword_ masters
	 * @throws SystemException if a system exception occurred
	 */
	public List<Keyword_Master> findAll(int start, int end,
		OrderByComparator orderByComparator) throws SystemException {
		FinderPath finderPath = null;
		Object[] finderArgs = new Object[] { start, end, orderByComparator };

		if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
				(orderByComparator == null)) {
			finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
			finderArgs = FINDER_ARGS_EMPTY;
		}
		else {
			finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
			finderArgs = new Object[] { start, end, orderByComparator };
		}

		List<Keyword_Master> list = (List<Keyword_Master>)FinderCacheUtil.getResult(finderPath,
				finderArgs, this);

		if (list == null) {
			StringBundler query = null;
			String sql = null;

			if (orderByComparator != null) {
				query = new StringBundler(2 +
						(orderByComparator.getOrderByFields().length * 3));

				query.append(_SQL_SELECT_KEYWORD_MASTER);

				appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
					orderByComparator);

				sql = query.toString();
			}
			else {
				sql = _SQL_SELECT_KEYWORD_MASTER;
			}

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				if (orderByComparator == null) {
					list = (List<Keyword_Master>)QueryUtil.list(q,
							getDialect(), start, end, false);

					Collections.sort(list);
				}
				else {
					list = (List<Keyword_Master>)QueryUtil.list(q,
							getDialect(), start, end);
				}
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (list == null) {
					FinderCacheUtil.removeResult(finderPath, finderArgs);
				}
				else {
					cacheResult(list);

					FinderCacheUtil.putResult(finderPath, finderArgs, list);
				}

				closeSession(session);
			}
		}

		return list;
	}

	/**
	 * Removes the keyword_ master where KeyId = &#63; from the database.
	 *
	 * @param KeyId the key ID
	 * @return the keyword_ master that was removed
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master removeByFindKeywordById(long KeyId)
		throws NoSuchKeyword_MasterException, SystemException {
		Keyword_Master keyword_Master = findByFindKeywordById(KeyId);

		return remove(keyword_Master);
	}

	/**
	 * Removes the keyword_ master where KeywordName = &#63; from the database.
	 *
	 * @param KeywordName the keyword name
	 * @return the keyword_ master that was removed
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master removeByFindKeywordByName(String KeywordName)
		throws NoSuchKeyword_MasterException, SystemException {
		Keyword_Master keyword_Master = findByFindKeywordByName(KeywordName);

		return remove(keyword_Master);
	}

	/**
	 * Removes the keyword_ master where KeywordName = &#63; and Created_By = &#63; from the database.
	 *
	 * @param KeywordName the keyword name
	 * @param Created_By the created_ by
	 * @return the keyword_ master that was removed
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master removeByFindKeywordByName_createdBy(
		String KeywordName, long Created_By)
		throws NoSuchKeyword_MasterException, SystemException {
		Keyword_Master keyword_Master = findByFindKeywordByName_createdBy(KeywordName,
				Created_By);

		return remove(keyword_Master);
	}

	/**
	 * Removes the keyword_ master where KeywordName = &#63; and isActive = &#63; from the database.
	 *
	 * @param KeywordName the keyword name
	 * @param isActive the is active
	 * @return the keyword_ master that was removed
	 * @throws SystemException if a system exception occurred
	 */
	public Keyword_Master removeByFindKeywordByName_isActive(
		String KeywordName, boolean isActive)
		throws NoSuchKeyword_MasterException, SystemException {
		Keyword_Master keyword_Master = findByFindKeywordByName_isActive(KeywordName,
				isActive);

		return remove(keyword_Master);
	}

	/**
	 * Removes all the keyword_ masters from the database.
	 *
	 * @throws SystemException if a system exception occurred
	 */
	public void removeAll() throws SystemException {
		for (Keyword_Master keyword_Master : findAll()) {
			remove(keyword_Master);
		}
	}

	/**
	 * Returns the number of keyword_ masters where KeyId = &#63;.
	 *
	 * @param KeyId the key ID
	 * @return the number of matching keyword_ masters
	 * @throws SystemException if a system exception occurred
	 */
	public int countByFindKeywordById(long KeyId) throws SystemException {
		Object[] finderArgs = new Object[] { KeyId };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYID,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_KEYWORD_MASTER_WHERE);

			query.append(_FINDER_COLUMN_FINDKEYWORDBYID_KEYID_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				qPos.add(KeyId);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYID,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of keyword_ masters where KeywordName = &#63;.
	 *
	 * @param KeywordName the keyword name
	 * @return the number of matching keyword_ masters
	 * @throws SystemException if a system exception occurred
	 */
	public int countByFindKeywordByName(String KeywordName)
		throws SystemException {
		Object[] finderArgs = new Object[] { KeywordName };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(2);

			query.append(_SQL_COUNT_KEYWORD_MASTER_WHERE);

			if (KeywordName == null) {
				query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_KEYWORDNAME_1);
			}
			else {
				if (KeywordName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_KEYWORDNAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_KEYWORDNAME_2);
				}
			}

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (KeywordName != null) {
					qPos.add(KeywordName);
				}

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of keyword_ masters where KeywordName = &#63; and Created_By = &#63;.
	 *
	 * @param KeywordName the keyword name
	 * @param Created_By the created_ by
	 * @return the number of matching keyword_ masters
	 * @throws SystemException if a system exception occurred
	 */
	public int countByFindKeywordByName_createdBy(String KeywordName,
		long Created_By) throws SystemException {
		Object[] finderArgs = new Object[] { KeywordName, Created_By };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME_CREATEDBY,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_COUNT_KEYWORD_MASTER_WHERE);

			if (KeywordName == null) {
				query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_KEYWORDNAME_1);
			}
			else {
				if (KeywordName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_KEYWORDNAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_KEYWORDNAME_2);
				}
			}

			query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_CREATED_BY_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (KeywordName != null) {
					qPos.add(KeywordName);
				}

				qPos.add(Created_By);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME_CREATEDBY,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of keyword_ masters where KeywordName = &#63; and isActive = &#63;.
	 *
	 * @param KeywordName the keyword name
	 * @param isActive the is active
	 * @return the number of matching keyword_ masters
	 * @throws SystemException if a system exception occurred
	 */
	public int countByFindKeywordByName_isActive(String KeywordName,
		boolean isActive) throws SystemException {
		Object[] finderArgs = new Object[] { KeywordName, isActive };

		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME_ISACTIVE,
				finderArgs, this);

		if (count == null) {
			StringBundler query = new StringBundler(3);

			query.append(_SQL_COUNT_KEYWORD_MASTER_WHERE);

			if (KeywordName == null) {
				query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_KEYWORDNAME_1);
			}
			else {
				if (KeywordName.equals(StringPool.BLANK)) {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_KEYWORDNAME_3);
				}
				else {
					query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_KEYWORDNAME_2);
				}
			}

			query.append(_FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_ISACTIVE_2);

			String sql = query.toString();

			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(sql);

				QueryPos qPos = QueryPos.getInstance(q);

				if (KeywordName != null) {
					qPos.add(KeywordName);
				}

				qPos.add(isActive);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FINDKEYWORDBYNAME_ISACTIVE,
					finderArgs, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Returns the number of keyword_ masters.
	 *
	 * @return the number of keyword_ masters
	 * @throws SystemException if a system exception occurred
	 */
	public int countAll() throws SystemException {
		Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
				FINDER_ARGS_EMPTY, this);

		if (count == null) {
			Session session = null;

			try {
				session = openSession();

				Query q = session.createQuery(_SQL_COUNT_KEYWORD_MASTER);

				count = (Long)q.uniqueResult();
			}
			catch (Exception e) {
				throw processException(e);
			}
			finally {
				if (count == null) {
					count = Long.valueOf(0);
				}

				FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
					FINDER_ARGS_EMPTY, count);

				closeSession(session);
			}
		}

		return count.intValue();
	}

	/**
	 * Initializes the keyword_ master persistence.
	 */
	public void afterPropertiesSet() {
		String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
					com.liferay.util.service.ServiceProps.get(
						"value.object.listener.com.caresms.model.Keyword_Master")));

		if (listenerClassNames.length > 0) {
			try {
				List<ModelListener<Keyword_Master>> listenersList = new ArrayList<ModelListener<Keyword_Master>>();

				for (String listenerClassName : listenerClassNames) {
					listenersList.add((ModelListener<Keyword_Master>)InstanceFactory.newInstance(
							listenerClassName));
				}

				listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
			}
			catch (Exception e) {
				_log.error(e);
			}
		}
	}

	public void destroy() {
		EntityCacheUtil.removeCache(Keyword_MasterImpl.class.getName());
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
		FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}

	@BeanReference(type = Category_MasterPersistence.class)
	protected Category_MasterPersistence category_MasterPersistence;
	@BeanReference(type = City_MasterPersistence.class)
	protected City_MasterPersistence city_MasterPersistence;
	@BeanReference(type = Country_MasterPersistence.class)
	protected Country_MasterPersistence country_MasterPersistence;
	@BeanReference(type = Keyword_MasterPersistence.class)
	protected Keyword_MasterPersistence keyword_MasterPersistence;
	@BeanReference(type = Keyword_Sms_RelationPersistence.class)
	protected Keyword_Sms_RelationPersistence keyword_Sms_RelationPersistence;
	@BeanReference(type = Sms_MasterPersistence.class)
	protected Sms_MasterPersistence sms_MasterPersistence;
	@BeanReference(type = ResourcePersistence.class)
	protected ResourcePersistence resourcePersistence;
	@BeanReference(type = UserPersistence.class)
	protected UserPersistence userPersistence;
	private static final String _SQL_SELECT_KEYWORD_MASTER = "SELECT keyword_Master FROM Keyword_Master keyword_Master";
	private static final String _SQL_SELECT_KEYWORD_MASTER_WHERE = "SELECT keyword_Master FROM Keyword_Master keyword_Master WHERE ";
	private static final String _SQL_COUNT_KEYWORD_MASTER = "SELECT COUNT(keyword_Master) FROM Keyword_Master keyword_Master";
	private static final String _SQL_COUNT_KEYWORD_MASTER_WHERE = "SELECT COUNT(keyword_Master) FROM Keyword_Master keyword_Master WHERE ";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYID_KEYID_2 = "keyword_Master.KeyId = ?";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_KEYWORDNAME_1 = "keyword_Master.KeywordName IS NULL";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_KEYWORDNAME_2 = "keyword_Master.KeywordName = ?";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_KEYWORDNAME_3 = "(keyword_Master.KeywordName IS NULL OR keyword_Master.KeywordName = ?)";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_KEYWORDNAME_1 =
		"keyword_Master.KeywordName IS NULL AND ";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_KEYWORDNAME_2 =
		"keyword_Master.KeywordName = ? AND ";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_KEYWORDNAME_3 =
		"(keyword_Master.KeywordName IS NULL OR keyword_Master.KeywordName = ?) AND ";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_CREATEDBY_CREATED_BY_2 =
		"keyword_Master.Created_By = ?";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_KEYWORDNAME_1 =
		"keyword_Master.KeywordName IS NULL AND ";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_KEYWORDNAME_2 =
		"keyword_Master.KeywordName = ? AND ";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_KEYWORDNAME_3 =
		"(keyword_Master.KeywordName IS NULL OR keyword_Master.KeywordName = ?) AND ";
	private static final String _FINDER_COLUMN_FINDKEYWORDBYNAME_ISACTIVE_ISACTIVE_2 =
		"keyword_Master.isActive = ?";
	private static final String _ORDER_BY_ENTITY_ALIAS = "keyword_Master.";
	private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Keyword_Master exists with the primary key ";
	private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Keyword_Master exists with the key {";
	private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
				PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
	private static Log _log = LogFactoryUtil.getLog(Keyword_MasterPersistenceImpl.class);
	private static Keyword_Master _nullKeyword_Master = new Keyword_MasterImpl() {
			@Override
			public Object clone() {
				return this;
			}

			@Override
			public CacheModel<Keyword_Master> toCacheModel() {
				return _nullKeyword_MasterCacheModel;
			}
		};

	private static CacheModel<Keyword_Master> _nullKeyword_MasterCacheModel = new CacheModel<Keyword_Master>() {
			public Keyword_Master toEntityModel() {
				return _nullKeyword_Master;
			}
		};
}